package com.fadis;

import java.util.concurrent.*;

public class FadisThread {

    public static final ExecutorService singleThread = Executors.newSingleThreadExecutor();
    public static final ExecutorService aofThread = Executors.newSingleThreadExecutor();

    public static <T> T runInAofThread(Callable<T> r){
        Future<T> future = aofThread.submit(r);
        try {
            return future.get();
        } catch (InterruptedException e) {
            throw new FadisException(4100, e.getMessage());
        } catch (ExecutionException e) {
            throw new FadisException(4100, e.getMessage());
        }
    }

    public static <T> T runInRedisThread(Callable<T> r){
        Future<T> future = singleThread.submit(r);
        try {
            return future.get();
        } catch (InterruptedException e) {
            throw new FadisException(4100, e.getMessage());
        } catch (ExecutionException e) {
            throw new FadisException(4100, e.getMessage());
        }
    }
    public static <T> T runInCurrent(Callable<T> r){
        try {
            return r.call();
        } catch (Exception e) {
            throw new FadisException(4100, e.getMessage());
        }
    }



}
